package com.example.mobile2032021606170hsy0506;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.service.autofill.FillEventHistory;
import android.view.VerifiedInputEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity  implements View.OnClickListener {

    private TextView tvMainTitle;
    private EditText edtTxtMainlnput;
    private Button btnMainIE;
    private Button btnMainCall;
    private Button btnMainCamera;
    private Button btnMainMap;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
    @Override
    public void onClick(View v) {
        switch  (v.getId()){
            case R.id.btnMainIE:
                String input=edtTxtMainlnput.getText().toString().trim();
                Uri uri=Uri.parse(input);
                Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);
                break;
            case  R.id.btnMainCall:
               input=edtTxtMainlnput.getText().toString().trim();
               uri = Uri.parse("tel:"+input);
               intent =new Intent(Intent.ACTION_DIAL,uri);
               startActivity(intent);
               break;
            case  R.id.btnMainCamera:
                input=edtTxtMainlnput.getText().toString().trim();
                intent= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivity(intent);
                break;
            case  R.id.btnMainMap:
                input=edtTxtMainlnput.getText().toString().trim();
                uri = Uri.parse("geo:"+ input);
                intent= new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);
                break;
        }
    }
    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tvMainTitle);
        edtTxtMainlnput = (EditText) findViewById(R.id.edtTxtMainlnput);
        btnMainIE = (Button) findViewById(R.id.btnMainIE);
        btnMainCall = (Button) findViewById(R.id.btnMainCall);
        btnMainCamera = (Button) findViewById(R.id.btnMainCamera);
        btnMainMap = (Button) findViewById(R.id.btnMainMap);
        btnMainIE.setOnClickListener(this);
        btnMainCall.setOnClickListener(this);
        btnMainCamera.setOnClickListener(this);
        btnMainMap.setOnClickListener(this);
    }

}